package com.kede.api.order.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

/***
 ** @Author:Pr.li
 ** @Description:
 ** @Date: create in 2023/5/5 16:13
 ***/
@Component
public class DateUpdateConfig implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Long l = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
        int time = Integer.valueOf(l.toString());
        this.setFieldValByName("createtime",time,metaObject);
        this.setFieldValByName("updatetime",time,metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        Long l = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
        int time = Integer.valueOf(l.toString());
        this.setFieldValByName("updatetime",time,metaObject);
    }
}
